home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / FAUG / FAUG03.ADF / Automata (.txt) < prev    next >
AmigaBASIC Source Code  |  1986-02-21  |  8KB  |  372 lines

  1. Start:
  2.  
  3. 'Cellualar Automata
  4. 'By Flynn D. Fishman
  5. 'January 1985
  6. 'Feel Free to copy this program and give it to friends
  7.  
  8. ON ERROR GOTO Bug 
  9. ERROR ON
  10.  
  11. size=320
  12. SCREEN 2,size,200,5,1
  13. WINDOW 2,"Automata",(0,0)-(297,185),1,2 
  14. PALETTE 0,0,0,0
  15. PALETTE 1,1,0,0
  16. PALETTE 2,0,1,0
  17. PALETTE 3,0,0,1
  18. PALETTE 4,1,0.75,0
  19. PALETTE 5,1,0,0.75
  20. PALETTE 6,0,0.75,1
  21. PALETTE 7,1,1,1
  22. PALETTE 8,0.5,1,0.5
  23. PALETTE 9,1,0.5,0.5
  24. PALETTE 31,0,1,1
  25. PALETTE 30,0.5,0.1,0.2
  26. COLOR 2
  27. PRINT"Cellular Automata"
  28. COLOR 7
  29. PRINT"By Flynn D. Fishman"
  30. COLOR 4
  31. PRINT"Courtesy
  32. PRINT"Of Phase 4 Distributors Inc. Canada
  33. PRINT
  34. COLOR 5
  35. PRINT "Please Wait Loading Sprite's"
  36. OPEN "Top.spr" FOR INPUT AS 1
  37. OBJECT.SHAPE 1,INPUT$(LOF(1),1)
  38. CLOSE 1
  39. OPEN "Bottom.spr" FOR INPUT AS 1
  40. OBJECT.SHAPE 2,INPUT$(LOF(1),1)
  41. CLOSE 1
  42. WINDOW 3,"Data",(3,3)-(150,19),,2
  43. WINDOW OUTPUT 2
  44. size=300
  45. CLS
  46. LOCATE 5,1
  47. COLOR 7
  48. PRINT"Did You Want An Explanation?"
  49. a$=""
  50. WHILE a$=""
  51.   a$=INKEY$
  52. WEND
  53. IF a$="y" OR a$="Y" THEN GOSUB explanation
  54.  
  55. DIM rule(100),li%(90)
  56. LINE (2,165)-(2,175),11
  57. PSET (2,170),0
  58. GET (2,165)-(2,175),li%
  59. PUT (2,165),li%
  60.  
  61. Set.Defaults:
  62.   rule$="101"
  63.   PSET (size/2,170),1  
  64.   xorigion=size/2-4
  65.   yorigion=160
  66.   
  67. GOSUB Set.Behaviour
  68. y=171
  69. GOSUB Set.Up.First.Generation
  70.  
  71. MENU 1,0,1,"Alterations"
  72. MENU 1,1,1,"Change Rules           "
  73. MENU 1,2,1,"Edit Current Generation"
  74. MENU 1,3,1,"Reset Program          "
  75. MENU 1,4,1,"Pause Program          "
  76. MENU 1,5,1,"Color Table            "
  77. MENU 1,6,1,"Turn Zoom On           "
  78. MENU 1,7,1,"Explanation            "
  79. MENU 1,8,1,"Exit to System         "                   
  80. FOR m=2 TO 4
  81.   MENU m,0,1,""
  82. NEXT
  83. LOCATE 10,1
  84.   PRINT "Use The Pull Down Menus To"
  85.   PRINT "See The options"
  86.  
  87. ON MENU GOSUB Change: MENU ON
  88.  
  89. Initialize:
  90.   generation=1
  91.     WINDOW OUTPUT 3
  92.     LOCATE 1,1
  93.     COLOR 5
  94.     PRINT"Life System:";rule$
  95.     COLOR 6 
  96.     PRINT"Generation :";generation;
  97. WINDOW OUTPUT 2
  98.   
  99. Life.Loop:  
  100.   FOR y=171 TO 178
  101.   living=0
  102.   LINE (1,y)-(size,y),10
  103.     FOR x=1 TO size
  104.       cell=rule(POINT(x-1,y-1)+POINT(x,y-1)+POINT(x+1,y-1))
  105.       living=living+cell
  106.       PSET (x,y),cell
  107.     NEXT x
  108.     generation=generation+1
  109.     WINDOW OUTPUT 3
  110.     LOCATE 1,1
  111.     COLOR 5
  112.     PRINT"Life System:";rule$
  113.     COLOR 6 
  114.     PRINT"Generation :";generation;
  115.     WINDOW OUTPUT 2
  116.     IF living=0 THEN
  117.       WHILE 1=1
  118.         FOR i=1 TO 31
  119.           COLOR i
  120.           LOCATE 4,1
  121.           PRINT "This system died on Generation"generation
  122.         NEXT
  123.       WEND
  124.     END IF
  125.   NEXT y
  126.   LOCATE 25,1
  127.   PRINT
  128.   IF Zoom=1 THEN GOSUB Update.Zoom
  129. GOTO Life.Loop
  130.  
  131. Change:
  132.   ON MENU(1) GOSUB Set.Behaviour,Set.Up.First.Generation,Start.Over,Pause,Color.Table,Toggle.Zoom,explanation,Bye
  133.   RETURN  
  134.  
  135. Set.Behaviour:
  136.   WINDOW 5,"Try These",(10,50)-(290,106),,2
  137.   COLOR 4
  138.   PRINT"Try These"
  139.   COLOR 5
  140.   PRINT"22133105  42004105  331240
  141.   PRINT"202432105 33111003204 12011203
  142.   COLOR 4
  143.   PRINT"Try These with a Random Generation
  144.   COLOR 5
  145.   PRINT"11004005  22310005  131205
  146.   PRINT"32113105
  147.   WINDOW 4,"Please Enter Rule:",(3,3)-(180,19),,2
  148.   LOCATE 1,1
  149.   COLOR 2
  150.   PRINT "  "rule$;
  151.   LOCATE 1,1
  152.   INPUT a$
  153.   IF a$="" THEN a$=rule$
  154.   rule$=a$
  155.   WINDOW CLOSE 5
  156.   WINDOW CLOSE 4
  157.   FOR i=LEN(rule$)-1 TO 1 STEP -1
  158.     rule(LEN(rule$)-i-1)=VAL(MID$(rule$,i,1))
  159.   NEXT
  160. RETURN
  161.  
  162. Set.Up.First.Generation:
  163.   WINDOW 5,"Instructions",(1,1)-(290,60),1,2
  164.   COLOR 4
  165.   PRINT "Set Up The First Generation"
  166.   COLOR 3
  167.   PRINT "Move Indicator with the Mouse"
  168.   PRINT "-Left Button or Return when Finished"
  169.   PRINT "-Any Number To Define That cell"
  170.   PRINT "-C to Clear the Line
  171.   PRINT "-R to set up a Random Generation"
  172.   WINDOW OUTPUT 2
  173.   last=MOUSE(1)
  174.   PUT (last,y-6),li% 
  175.   Define.Start:
  176.     IF MOUSE(1)<>last THEN
  177.       PUT (last,y-6),li% 
  178.       last=MOUSE(1)
  179.       PUT (last,y-6),li%
  180.     END IF
  181.     a$=INKEY$
  182.     IF a$="C" OR a$="c" THEN LINE (0,y-1)-(size,y-1),0
  183.     IF a$=>"0" AND a$<="9" THEN PSET (last,y-1),VAL(a$)
  184.     IF a$="r" OR a$="R" THEN
  185.       max=0
  186.       FOR i=1 TO LEN(rule$)
  187.         IF VAL(MID$(rule$,i,1))>max THEN max=VAL(MID$(rule$,i,1))
  188.       NEXT i
  189.       FOR i=1 TO size
  190.        PSET (i,y-1),INT(RND(2)*max+0.5)
  191.       NEXT i
  192.     END IF
  193.     IF a$<>CHR$(13) AND MOUSE(0)<>-1 THEN Define.Start
  194.   PUT (last,y-6),li%
  195.   WINDOW CLOSE 5
  196. RETURN
  197.  
  198. Start.Over:
  199.   RUN
  200.  
  201. Bye:
  202.   SYSTEM
  203.    
  204. Pause:
  205.   WINDOW 4,"Pause On",(0,0)-(260,10)
  206.   PRINT "Press The Mouse Button To UnPause";
  207.   WHILE MOUSE(0)<>-1
  208.     'Do Nothing
  209.   WEND
  210.   WINDOW CLOSE 4
  211. RETURN
  212.  
  213. Color.Table:
  214.   WINDOW 4,"Color Table",(0,0)-(280,10)
  215.   FOR x=1 TO 9
  216.     COLOR 0,x
  217.     PRINT" ";
  218.     COLOR x,0
  219.     PRINT"-";RIGHT$(STR$(x),1);" ";
  220.   NEXT
  221.   WHILE MOUSE(0)<>-1
  222.     'Do Nothing
  223.   WEND
  224.   WINDOW CLOSE 4
  225. RETURN
  226.  
  227. Bug:
  228.   'do nothing
  229.   RESUME NEXT
  230.   
  231. Toggle.Zoom:
  232.   IF Zoom=1 THEN
  233.     Zoom=0
  234.     WINDOW OUTPUT 2
  235.     WINDOW CLOSE 4
  236.     OBJECT.OFF 1,2
  237.     MOUSE OFF
  238.     MENU 1,6,1,"Turn Zoom On           "
  239.   ELSE
  240.     Zoom=1
  241.     OBJECT.ON 1,2
  242.     WINDOW 4,"Zoom",(2,2)-(100,100)
  243.     GOSUB Update.Zoom
  244.     ON MOUSE GOSUB Move.Zoom.Window
  245.     MOUSE ON
  246.     MENU 1,6,1,"Turn Zoom Off          "
  247.   END IF
  248. RETURN
  249.  
  250. Update.Zoom:
  251.   WINDOW OUTPUT 4
  252.   LOCATE 1,1
  253.   xaccross=INT(WINDOW(2)/8)-1
  254.   yaccross=INT(WINDOW(3)/8)-1
  255.   WINDOW OUTPUT 2
  256.   OBJECT.X 1,xorigion-3
  257.   OBJECT.Y 1,yorigion+6
  258.   OBJECT.X 2,xorigion+xaccross-6
  259.   OBJECT.Y 2,yorigion+yaccross-1
  260.   FOR yzoom=1 TO yaccross
  261.     FOR xzoom = 1 TO xaccross
  262.       WINDOW OUTPUT 2
  263.       Col=POINT (xzoom+xorigion,yzoom+yorigion)
  264.  '    PSET (xzoom+xorigion,yzoom+yorigion),15
  265.       WINDOW OUTPUT 4
  266.       COLOR Col
  267.       PRINT "*";
  268.     NEXT xzoom
  269.     PRINT
  270.   NEXT yzoom
  271.   WINDOW OUTPUT 2
  272. RETURN  
  273.   
  274. Move.Zoom.Window:
  275.   WINDOW OUTPUT 4
  276.   xaccross=INT(WINDOW(2)/8)-1
  277.   yaccross=INT(WINDOW(3)/8)-1
  278.   WINDOW OUTPUT 2
  279.   WHILE MOUSE (0)=-1
  280.     xorigion=MOUSE(1)
  281.     yorigion=MOUSE(2)
  282.     OBJECT.X 1,xorigion-3
  283.     OBJECT.Y 1,yorigion+6
  284.     OBJECT.X 2,xorigion+xaccross-6
  285.     OBJECT.Y 2,yorigion+yaccross-1
  286.   WEND
  287.   GOSUB Update.Zoom
  288.   RETURN
  289.   
  290. explanation:
  291.   WINDOW OUTPUT 2
  292.   WINDOW 5,"Explanation",(0,0)-(297,48),,2
  293.   DATA"Cellular Automata is a branch of 
  294.   DATA"'Mathematics' where a 'Life System'
  295.   DATA"Is given a set of rules in
  296.   DATA"Numerical form from which that system
  297.   DATA"Should exist by.
  298.   DATA"I obtained most of my information
  299.   DATA"For this science from an article 
  300.   DATA"By Stephen Wolfram (a major force in
  301.   DATA"Mathematical Computer Simulations
  302.   DATA"Including Automata) I believe that 
  303.   DATA"The article was in a 1985 issue of
  304.   DATA"Scientific America page 188-203 
  305.   DATA"'Computer Software in Science and
  306.   DATA"Mathematics'. I am sorry that I can 
  307.   DATA"Not be more specific on the date.
  308.   DATA"In a Cellular Automata the history 
  309.   DATA"Of a life system scrolls up the 
  310.   DATA"Screen.  Each cell is represented 
  311.   DATA"By a colored dot.  The color of the 
  312.   DATA"Dot represents the density of that 
  313.   DATA"Area of the life system.  The density
  314.   DATA"Of a cell is calculated by the sum 
  315.   DATA"Of the density of the two neighboring
  316.   DATA"Cells and the current cell.  It is 
  317.   DATA"Then displayed on the line directly 
  318.   DATA"Underneath the current generation. 
  319.   DATA"The rules for the system is based 
  320.   DATA"On a numerical digit comprised of
  321.   DATA"Several digits from 0 to 9.  The 
  322.   DATA"Far right number represents the number
  323.   DATA"System you are working with.  For 
  324.   DATA"Example if the last number is 3 
  325.   DATA"Then you will not have a density 
  326.   DATA"Higher than that number.
  327.   DATA"The other digits in the rule represents 
  328.   DATA"The density of a particular
  329.   DATA"Cell working right to left.  For 
  330.   DATA"Example when working with the 
  331.   DATA"'3104' the number system is 4.  If 
  332.   DATA"The sum of a cells neighbours is 0
  333.   DATA"Then that cell has a density of 0.  
  334.   DATA"If the neighbours' sum is 1 then the
  335.   DATA"Density of that cell would be 1.  
  336.   DATA"And if the sum=2 then the density=3
  337.   DATA"Note that when zoom is on you can
  338.   DATA"Move the zoom window by pointing to
  339.   DATA"Arrow at the new location and 
  340.   DATA"The left button"
  341.   DATA""
  342.   DATA"Please Click The Mouse to Continue"
  343.   DATA"end"
  344.   LOCATE 1,1
  345.   COLOR 2
  346.   PRINT"To Pause the Explanation
  347.   PRINT"Click the RIGHT button"
  348.   COLOR 3
  349.   PRINT"Click the Left Button To Begin"
  350.   WHILE MOUSE(0)<>-1
  351.     'Do Nothing
  352.   WEND
  353.   COLOR 4
  354.   RESTORE
  355.   READ da$
  356.   WHILE da$<>"end"
  357.     LOCATE 6,1
  358.     PRINT da$;
  359.     READ da$
  360.     FOR sc= 1 TO 8
  361.       SCROLL (0,0)-(320,48),0,-1
  362.     NEXT sc
  363.   WEND
  364.    WHILE MOUSE(0)<>-1
  365.     'Do Nothing
  366.   WEND
  367.  IF Zoom=1 THEN MOUSE ON
  368.   WINDOW OUTPUT 2
  369.   WINDOW CLOSE 5
  370.   RETURN
  371.  
  372.